package professor;

import java.io.IOException;
import java.io.StringReader;

import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.analysis.br.BrazilianAnalyzer;
import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
import org.apache.lucene.util.Version;

public class ProfessorUtils {
	
	public static String getFormattedString(String text) throws IOException{
		
		Analyzer ba = new BrazilianAnalyzer(Version.LUCENE_34);
		
		StringReader sr = new StringReader(text);
		
		TokenStream tokenStream = ba.tokenStream(null, sr);
		CharTermAttribute charTermAttribute = tokenStream.getAttribute(CharTermAttribute.class);

		StringBuilder sb = new StringBuilder("");
		String term;
		while (tokenStream.incrementToken()) {
		    term = charTermAttribute.toString();
		    sb.append(term).append(" ");
		}		
		return sb.toString();
	}
}
